﻿using System.Diagnostics;
using System.Runtime.InteropServices;

namespace FileSystemTest
{
    internal class Program
    {

        //生成文件读写测试代码，包括创建文件，写入内容，读取内容，删除文件等操作。
        static void FileTest()
        {
            var filePath = "test.txt";
            // 创建文件并写入内容
            System.IO.File.WriteAllText(filePath, "Hello, World!");
            // 读取文件内容
            var content = System.IO.File.ReadAllText(filePath);
            Console.WriteLine(content);
            // 删除文件
            System.IO.File.Delete(filePath);
        }
        static void DirectoryTest()
        {
            var dirPath = "TestDir";
            // 创建目录
            System.IO.Directory.CreateDirectory(dirPath);
            // 创建子目录
            var subDirPath = System.IO.Path.Combine(dirPath, "SubDir");
            System.IO.Directory.CreateDirectory(subDirPath);
            // 删除目录
            System.IO.Directory.Delete(dirPath, true);
        }
        //定义一个Dll import
        [DllImport("*")]
        internal static extern unsafe void SetIcsNativeaotActiveCode(byte[] activeCode);
        static void Main(string[] args)
        {
            var activeCode = new byte[] { 0x3B, 0xD9, 0xDD, 0xF5, 0x00, 0xCE, 0x42, 0x8D, 0x5D, 0xAA, 0xEA, 0x90, 0x81, 0xB8, 0xEE, 0x80, 0xAB, 0xCD, 0x78, 0x71, 0xA3, 0xB1, 0x97, 0x4F, 0x9C, 0x01, 0xCE, 0xE2, 0x58, 0x0A, 0x84, 0xB1, };
            //获取当前platform
            var platform = RuntimeInformation.ProcessArchitecture;
            if (platform == Architecture.Arm)
            {
                SetIcsNativeaotActiveCode(activeCode);
            }
            //设置/mnt/sd0/user目录为当前工作目录
            System.IO.Directory.SetCurrentDirectory("/mnt/sd0/home");
            FileTest();
            DirectoryTest();

        }   
    }
}
